package com.bit.demo01;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @program: 2022.2.23 类和对象
 * @description:
 * @author: 李鑫月
 * @create: 2022-02-24 18:08
 **/
class Student implements Comparable<Student>{
    String name;
    double score;
    int age;
    public Student(String name,double score,int age){

        this.name=name;
        this.age=age;
        this.score=score;
    }
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return this.name.compareTo(o.name);
    }
}
class AgeComparator implements java.util.Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}
class NameComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
public class TeseDemo {
    public static void main(String[] args) {
        Student[] students=new Student[]{
        new Student("zhangsan",90.5,11),
        new Student("lisi",30.5,21),
        new Student("wangwu",40.5,31),

        };

        
        AgeComparator ageComparator=new AgeComparator();
        NameComparator nameComparator=new NameComparator();
        Arrays.sort(students,ageComparator);
        System.out.println(Arrays.toString(students));
        Arrays.sort(students,nameComparator);
        System.out.println(Arrays.toString(students));

    }

}
